﻿using System;
using System.Data;
using System.Collections.Generic;
using Maticsoft.Common;
using ChinaSoft.Model;
namespace ChinaSoft.BLL
{
	/// <summary>
	/// BLL_tb_MidSoft_FinanceSubInvoice
	/// </summary>
	public partial class BLL_tb_MidSoft_FinanceSubInvoice
	{
		private readonly ChinaSoft.DAL.DAL_tb_MidSoft_FinanceSubInvoice dal=new ChinaSoft.DAL.DAL_tb_MidSoft_FinanceSubInvoice();
		public BLL_tb_MidSoft_FinanceSubInvoice()
		{}
		#region  Method

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
			return dal.GetMaxId();
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int SubInvoiceId)
		{
			return dal.Exists(SubInvoiceId);
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int  Add(ChinaSoft.Model.Model_tb_MidSoft_FinanceSubInvoice model)
		{
			return dal.Add(model);
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(ChinaSoft.Model.Model_tb_MidSoft_FinanceSubInvoice model)
		{
			return dal.Update(model);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int SubInvoiceId)
		{
			
			return dal.Delete(SubInvoiceId);
		}
		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool DeleteList(string SubInvoiceIdlist )
		{
			return dal.DeleteList(SubInvoiceIdlist );
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public ChinaSoft.Model.Model_tb_MidSoft_FinanceSubInvoice GetModel(int SubInvoiceId)
		{
			
			return dal.GetModel(SubInvoiceId);
		}

		/// <summary>
		/// 得到一个对象实体，从缓存中
		/// </summary>
		public ChinaSoft.Model.Model_tb_MidSoft_FinanceSubInvoice GetModelByCache(int SubInvoiceId)
		{
			
			string CacheKey = "Model_tb_MidSoft_FinanceSubInvoiceModel-" + SubInvoiceId;
			object objModel = Maticsoft.Common.DataCache.GetCache(CacheKey);
			if (objModel == null)
			{
				try
				{
					objModel = dal.GetModel(SubInvoiceId);
					if (objModel != null)
					{
						int ModelCache = Maticsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
						Maticsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
					}
				}
				catch{}
			}
			return (ChinaSoft.Model.Model_tb_MidSoft_FinanceSubInvoice)objModel;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}
		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			return dal.GetList(Top,strWhere,filedOrder);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<ChinaSoft.Model.Model_tb_MidSoft_FinanceSubInvoice> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<ChinaSoft.Model.Model_tb_MidSoft_FinanceSubInvoice> DataTableToList(DataTable dt)
		{
			List<ChinaSoft.Model.Model_tb_MidSoft_FinanceSubInvoice> modelList = new List<ChinaSoft.Model.Model_tb_MidSoft_FinanceSubInvoice>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				ChinaSoft.Model.Model_tb_MidSoft_FinanceSubInvoice model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = new ChinaSoft.Model.Model_tb_MidSoft_FinanceSubInvoice();
					if(dt.Rows[n]["SubInvoiceId"]!=null && dt.Rows[n]["SubInvoiceId"].ToString()!="")
					{
						model.SubInvoiceId=int.Parse(dt.Rows[n]["SubInvoiceId"].ToString());
					}
					if(dt.Rows[n]["ProjectInfoId"]!=null && dt.Rows[n]["ProjectInfoId"].ToString()!="")
					{
						model.ProjectInfoId=int.Parse(dt.Rows[n]["ProjectInfoId"].ToString());
					}
					if(dt.Rows[n]["ContractId"]!=null && dt.Rows[n]["ContractId"].ToString()!="")
					{
						model.ContractId=int.Parse(dt.Rows[n]["ContractId"].ToString());
					}
					if(dt.Rows[n]["Customer"]!=null && dt.Rows[n]["Customer"].ToString()!="")
					{
					model.Customer=dt.Rows[n]["Customer"].ToString();
					}
					if(dt.Rows[n]["InvoiceNumber"]!=null && dt.Rows[n]["InvoiceNumber"].ToString()!="")
					{
					model.InvoiceNumber=dt.Rows[n]["InvoiceNumber"].ToString();
					}
					if(dt.Rows[n]["InvoiceDate"]!=null && dt.Rows[n]["InvoiceDate"].ToString()!="")
					{
						model.InvoiceDate=DateTime.Parse(dt.Rows[n]["InvoiceDate"].ToString());
					}
					if(dt.Rows[n]["ReceiveMan"]!=null && dt.Rows[n]["ReceiveMan"].ToString()!="")
					{
					model.ReceiveMan=dt.Rows[n]["ReceiveMan"].ToString();
					}
					if(dt.Rows[n]["InvoiceMoney"]!=null && dt.Rows[n]["InvoiceMoney"].ToString()!="")
					{
						model.InvoiceMoney=decimal.Parse(dt.Rows[n]["InvoiceMoney"].ToString());
					}
					if(dt.Rows[n]["CreateUser"]!=null && dt.Rows[n]["CreateUser"].ToString()!="")
					{
					model.CreateUser=dt.Rows[n]["CreateUser"].ToString();
					}
					if(dt.Rows[n]["CreateDepartment"]!=null && dt.Rows[n]["CreateDepartment"].ToString()!="")
					{
					model.CreateDepartment=dt.Rows[n]["CreateDepartment"].ToString();
					}
					if(dt.Rows[n]["CreateDate"]!=null && dt.Rows[n]["CreateDate"].ToString()!="")
					{
						model.CreateDate=DateTime.Parse(dt.Rows[n]["CreateDate"].ToString());
					}
					if(dt.Rows[n]["CreateUserId"]!=null && dt.Rows[n]["CreateUserId"].ToString()!="")
					{
						model.CreateUserId=int.Parse(dt.Rows[n]["CreateUserId"].ToString());
					}
					modelList.Add(model);
				}
			}
			return modelList;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}

		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			return dal.GetRecordCount(strWhere);
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			return dal.GetListByPage( strWhere,  orderby,  startIndex,  endIndex);
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		//public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		//{
			//return dal.GetList(PageSize,PageIndex,strWhere);
		//}

		#endregion  Method
	}
}

